package com.briup.estore.service.impl;

import com.briup.estore.bean.Book;
import com.briup.estore.bean.BookExample;
import com.briup.estore.bean.extend.BookExtend;
import com.briup.estore.dao.BookMapper;
import com.briup.estore.dao.CustomerMapper;
import com.briup.estore.dao.extend.BookExtendMapper;
import com.briup.estore.service.BookService;
import com.briup.estore.util.MybatisSqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class BookServiceImpl implements BookService {

    private BookMapper bookMapper;
    private BookExtendMapper bookExtendMapper;
    {
        SqlSession sqlSession = MybatisSqlSessionFactory.openSession();
        bookMapper = sqlSession.getMapper(BookMapper.class);
        bookExtendMapper =sqlSession.getMapper(BookExtendMapper.class);
    }

    @Override
    public List<Book> findAllBooks() {
        return bookMapper.selectByExample(new BookExample());
    }

    @Override
    public Book findBookById(Integer id) {
        return bookMapper.selectByPrimaryKey(id);
    }

    @Override
    public BookExtend findBookAndCategoryById(Integer id) {
        return bookExtendMapper.findById(id);
    }
}
